/**
 * 添加或修改商品尺寸信息
 * 
 * @param {}
 *            goodsPriceSizeId
 * @param {}
 *            title
 * @return {}
 */
function addOrUpdGoodsPriceSize(id, title, goodsId, goodsCode) {
	var addOrUpdGoodsPriceSizeForm = new Ext.form.FormPanel({
				id : 'addOrUpdGoodsPriceSizeForm',
				frame : true,
				layout : "form",
				buttonAlign : 'center',
				monitorValid : true,
				bodyBorder : false,
				fileUpload : true,// 上传文件设置为true
				reader : new Ext.data.JsonReader({
							success : 'success',
							root : 'data'
						}, [{
									name : 'id'
								}, {
									name : 'goodsId'
								}, {
									name : 'goodsPrice'
								}, {
									name : 'goodsSize'
								}, {
									name : 'goodsCode'
								}, {
									name : 'goodsOrder'
								}, {
									name : 'goodsUnits'
								}, {
									name : 'goodsWeight'
								}, {
									name : "createdDate"
								}, {
									name : "createdName"
								}, {
									name : "updatedDate"
								}, {
									name : "updatedName"
								}, {
									name : "giveLaidNumber"
								}, {
									name : "isDelete"
								}, {
									name : "goodsEatNumber"
								}]),
				items : [{
							xtype : 'hidden',
							name : 'id',
							value : id
						}, {
							xtype : 'hidden',
							name : 'goodsId',
							value : goodsId
						}, {
							id : 'priceSizeGoodsCode',
							xtype : 'hidden',
							name : 'goodsCode',
							value : goodsCode
						}, {
							xtype : 'numberfield',
							anchor : '100%',
							fieldLabel : "<span style='color:#F00'>*</span>商品单价",
							allowBlank : false,
							allowNegative : false,
							name : "goodsPrice",
							renderer : function(value) {
								return PmsUtil.priceRenderer(value);
							}
						},{
							xtype : "textfield",
							anchor : '100%',
							fieldLabel : "<span style='color:#F00'>*</span>适合人数",
							allowBlank : false,
							allowNegative : false,
							blankText : '适合人数不能为空',
							name : "goodsEatNumber"
						}, {
							layout : "column",
							border : false,
							anchor : '100%',
							fieldLabel : "<span style='color:#F00'>*</span>商品重量",
							items : [{
										id : 'goodsPSWeight',
										xtype : "combo",
										mode : "local",
										fieldLabel : "重量",
										width : 100,
										hiddenName : "goodsWeight",
										triggerAction : 'all',
										emptyText : "选择",
										editable : true,
										valueField : "value",
										displayField : "text",
										store : new Ext.data.SimpleStore({
													fields : ["value", "text"],
													data : [['1', "1"],
															['2', "2"]]
												})
									}, {
										id : 'upGoodsSize_goodsWeightUnits',
										xtype : 'combo',
										editable : false,
										width : 80,
										mode : 'local',
										triggerAction : 'all',
										valueField : "returnValue",
										displayField : "displayText",
										store : new Ext.data.SimpleStore({
													fields : ["returnValue",
															"displayText"],
													data : [['磅', '磅'],
															['个', '个'],
															['克', '克']]
												})
									}]
						}, {
							layout : "column",
							border : false,
							fieldLabel : "<span style='color:#F00'>*</span>商品尺寸",
							items : [{
										xtype : "displayfield",
										value : "宽:"
									}, {
										xtype : 'hidden',
										id : 'longWidth',
										name : 'goodsSize'
									}, {
										id : 'goodsPSLong',
										xtype : 'numberfield',
										width : 80,
										editable : false,
										autoLoad : true,
										allowBlank : false,
										defaultFirstRow : 1,
										allowDecimals : true,
										allowNegative : false, // 禁用负数
										minValue : 1,
										decimalPrecision : 1

									}, {
										xtype : 'displayfield',
										value : 'cm&nbsp;&nbsp;x&nbsp;&nbsp;高：'
									}, {
										id : 'goodsPSWidth',
										xtype : 'numberfield',
										width : 80,
										editable : false,
										autoLoad : true,
										allowBlank : false,
										defaultFirstRow : 1,
										allowDecimals : true,
										allowNegative : false, // 禁用负数
										minValue : 1,
										decimalPrecision : 1
										// 保留一位小数
								}	, {
										xtype : "displayfield",
										value : "cm"
									}]
						}, {
							id : 'upGoodsSize_goodsUnits',
							xtype : 'dataDictionaryCmb',
							anchor : '100%',
							fieldLabel : "<span style='color:#F00'>*</span>商品单位",
							hiddenName : "goodsUnits",
							editable : false,
							autoLoad : false,
							existall : false,
							defaultFirstRow : 1,
							dictionaryType : PmsUtil.fixing_units
						}, {
							id : 'goodsPriceSize_giveLaidNumber',
							xtype : 'numberfield',
							anchor : '100%',
							fieldLabel : "<span style='color:#F00'>*</span>赠送餐具数量",
							allowBlank : false,
							blankText : '赠送餐具数量不能为空',
							allowDecimals : false,// 禁用小数
							allowNegative : false, // 禁用负数
							minValue : 0,
							name : "giveLaidNumber"
						}, {
							id : 'addUpdGoodsOrder',
							xtype : 'numberfield',
							anchor : '100%',
							fieldLabel : "<span style='color:#F00'>*</span>排序",
							allowBlank : false,
							blankText : '排序不能为空',
							allowDecimals : false,// 禁用小数
							allowNegative : false, // 禁用负数
							minValue : 1,
							name : "goodsOrder"
						}, {
							xtype : 'hidden',
							name : 'isDelete'
						}],
				buttons : [{
							text : '确定',
							formBind : true,
							handler : function() {
								addOrUpdGoodsPS();
							}
						}, {
							text : "取消",
							handler : function() {
								addOrUpdGoodsPriceSizeWindow.close();
							}
						}]
			});
	var addOrUpdGoodsPriceSizeWindow = new Ext.Window({
				id : 'addOrUpdGoodsPriceSizeWindow',
				closeAction : 'close',
				title : title,
				closable : true,
				plain : true,
				modal : true,
				width : 400,
				height : 260,
				draggable : false, // 不可拖动
				resizable : false, // 不可调整
				buttonAlign : 'center',
				autoDestroy : true,
				layout : 'fit',
				items : [addOrUpdGoodsPriceSizeForm],
				listeners : {
					'show' : function() {
						selectGoodsPriceSizeUpdById(id);
					},
					'beforeshow' : function() {
						addOrUpdGoodsPriceSizeWindow.center();
					}
				}
			});
	return addOrUpdGoodsPriceSizeWindow;

};

/**
 * 查询商品尺寸信息
 * 
 * @param {}
 *            id
 */
function selectGoodsPriceSizeUpdById(id) {
	if (id != null && id != "undefined") {
		Ext.getCmp('addUpdGoodsOrder').getEl().up('.x-form-item')
				.setDisplayed(false);
		Ext.getCmp("addOrUpdGoodsPriceSizeForm").getForm().load({
			// deferredRender : false,
			url : __ctxPath + "/goodsManager/selectGoodsPriceSizeUpdById",
			params : {
				id : id
			},
			method : "POST",
			waitTitle : "请稍候",
			waitMsg : "正在载入数据...",
			root : "data",
			success : function(form, action) {
				var data = action.result.data;
				var goodsPSWeight = Ext.getCmp('goodsPSWeight');
				var goodsWeight = data.goodsWeight;
				var weight = Ext.util.Format.substr(goodsWeight, 0,
						goodsWeight.length - 1);

				// 设置宽高
				var goodsSizeStr = data.goodsSize;
				if (goodsSizeStr) {
					var lastIndex = goodsSizeStr.indexOf("cm");
					var goodsSize = goodsSizeStr.substring(0, lastIndex);
					var goodsSizeArray = goodsSize.split("x");
					Ext.getCmp("goodsPSLong").setValue(goodsSizeArray[0]);
					Ext.getCmp("goodsPSWidth").setValue(goodsSizeArray[1]);
				}

				// 设置重量
				goodsPSWeight.setValue(weight);
				goodsPSWeight.setRawValue(weight);// 显示的值

				// 设置重量单位
				var weightUnits = Ext.util.Format.substr(goodsWeight, 1,
						goodsWeight.length);
				Ext.getCmp("upGoodsSize_goodsWeightUnits")
						.setValue(weightUnits);

				// 设置商品编码
				var goodsCode = Ext.getCmp('priceSizeGoodsCode');
				goodsCode.setValue(data.goodsCode);

				// 设置赠送餐具最小值 默认为0
				if (data.giveLaidNumber == null) {
					var giveLaidNumber = Ext
							.getCmp('goodsPriceSize_giveLaidNumber');
					giveLaidNumber.setValue(0);
				}
			},
			failure : function(f, g) {
				Ext.MessageBox.show({
							title : "操作信息",
							msg : "数据加载失败!",
							buttons : Ext.MessageBox.OK,
							icon : Ext.MessageBox.ERROR
						});
			}
		});
	}
}
/**
 * 添加或修改商品尺寸信息
 */
function addOrUpdGoodsPS() {
	var longWidth = Ext.getCmp("longWidth");
	var goodsPSLong = Ext.getCmp("goodsPSLong").getValue();
	var goodsPSWidth = Ext.getCmp("goodsPSWidth").getValue();
	longWidth.setValue(goodsPSLong + "x" + goodsPSWidth + "cm");
	var goodsPSWeight = Ext.getCmp('goodsPSWeight').getValue();
	// 商品单位
	var goodsWeightUnits = Ext.getCmp("upGoodsSize_goodsWeightUnits")
			.getRawValue();
	Ext.getCmp('goodsPSWeight').setValue(goodsPSWeight + goodsWeightUnits);
	var addOrUpdGoodsPriceSizeForm = Ext.getCmp("addOrUpdGoodsPriceSizeForm");
	if (addOrUpdGoodsPriceSizeForm.getForm().isValid()) {
		Ext.Msg.confirm("提示框", "确认要保存商品尺寸信息吗?", function(button) {
					if (button == "yes") {
						addOrUpdGoodsPriceSizeForm.getForm().submit({
							url : __ctxPath
									+ '/goodsManager/addOrUpdGoodsPriceSize',
							waitTitle : "请稍候",
							waitMsg : "正在提交表单，请稍候......",
							failure : function(response, options) {
								var jsonData = Ext.util.JSON
										.decode(options.response.responseText);
								Ext.MessageBox.show({
											title : "错误提示",
											msg : jsonData.data,
											buttons : Ext.MessageBox.OK,
											icon : Ext.MessageBox.ERROR
										});
								Ext.getCmp('goodsPSWeight')
										.setValue(goodsPSWeight);

							},
							success : function(response, options) {
								Ext.getCmp('addUpdGoodsOrder').getEl()
										.up('.x-form-item').setDisplayed(true);
								var jsonData = Ext.util.JSON
										.decode(options.response.responseText);
								Ext.MessageBox.show({
											title : "信息提示",
											msg : jsonData.data,
											buttons : Ext.MessageBox.OK,
											icon : Ext.MessageBox.INFO
										});
								Ext.getCmp("addOrUpdGoodsPriceSizeWindow")
										.close();
								var gridPanel = Ext
										.getCmp('goodsPriceSizeGrid');
								if (typeof(gridPanel) != 'undefined') {
									gridPanel.store.reload();
								}
							}
						});
					}
				});
	}
}